var closeAuditOrderApi = {
    "getCloseAuditHtml": sysInfo.basePath + "/zzsc/completed/getCloseAuditOrderHtml.html", //获取对应子订单集合的订单信息页面
    "batchCloseAudit": sysInfo.basePath + "/zzsc/completed/batch_close_audit.do", //完结审核接口
}

function batchCloseAudit(){
    DGG.loading();
    //获取选中的订单id和产品id
    var data = $('#myCloseAuditTable').dataTableExtend('getCheck');
    //没有选择订单
    if (data.length > 10) {
        DGG.Errors('最多只能选择10条数据', 2000);
        DGG.loading('close');
        return false;
    }
    var ids = [];
    for (var i = 0; i < data.length; i++) {
        ids.push(data[i].id);//订单id
    }
    //没有选择订单
    if (isEmpty(ids)) {
        DGG.Errors('请选择进行完结审核的订单', 2000);
        DGG.loading('close');
        return false;
    }
    var params1 = {
        ids: ids//子订单id集合
    };
    $.post(closeAuditOrderApi.getCloseAuditHtml,params1,function (data) {
        DGG.loading('close');
        dgg.Open({
            content: data,
            type: 1,
            title: "完结审核",
            area: ["600px","450px"],
            btn: ['提交', '关闭'],
            success: function (layero, index) {
                DGG.loading('close');
            },
            yes: function (index, layero) {
                DGG.loading('close');
                var ids1 =[];
                $("input[name='subOrderIds']").each(function(){
                    ids1.push($(this).val());
                })
                if(isEmpty(ids1)){
                    ids1.push(ids[0]);
                }
                var params = {
                    remark:$("#remark").val(),
                    ids: ids1,//子订单id集合
                    type:$("input[name='auditResult']:checked").val()
                };
                if (isEmpty(params.type)) {
                    DGG.Errors('请选择审核结果！', 2000);
                    DGG.loading('close');
                    return false;
                }
                if(params.type == 0){
                    if(isEmpty(params.remark)){
                        DGG.Errors('驳回必须填写备注！', 2000);
                        DGG.loading('close');
                        return false;
                    }
                }
                DGG.Confire('确认执行此操作？', '操作提示', function () {
                    DGG.loading();
                    $.ajax({
                        url: closeAuditOrderApi.batchCloseAudit,
                        data: params,
                        success: function (result) {
                            if (result.code == 0) {
                                DGG.loading('close');
                                DGG.Succeed('操作成功!');
                                // tableObj.ajax.reload();
                                $("#myCloseAuditTable").dataTable().fnDraw(false);
                            } else {
                                DGG.loading('close');
                                DGG.Errors(result.msg)
                            }
                            layer.close(index);
                        }
                    });
                });
            },
            end: function () {
                DGG.loading('close');
            }
        })
    })
}

function closeAuditOrder(id){
    DGG.loading();
    var ids = [];
    ids.push(id);
    var params1 = {
        ids: ids,//子订单id集合
    };
    console.log(id);
    console.log(ids);
    $.post(closeAuditOrderApi.getCloseAuditHtml,params1,function (data) {
        DGG.loading('close');
        dgg.Open({
            content: data,
            type: 1,
            title: "完结审核",
            area: ["600px","450px"],
            btn: ['提交', '关闭'],
            success: function (layero, index) {
                DGG.loading('close');
            },
            yes: function (index, layero) {
                DGG.loading('close');
                var params = {
                    remark:$("#remark").val(),
                    ids: ids,//子订单id集合
                    type:$("input[name='auditResult']:checked").val()
                };
                if (isEmpty(params.type)) {
                    DGG.Errors('请选择审核结果！');
                    DGG.loading('close');
                    return false;
                }
                if(params.type == 0){
                    if(isEmpty(params.remark)){
                        DGG.Errors('驳回必须填写备注！', 2000);
                        DGG.loading('close');
                        return false;
                    }
                }
                DGG.Confire('确认执行此操作？', '操作提示', function () {
                    DGG.loading();
                    $.ajax({
                        url: closeAuditOrderApi.batchCloseAudit,
                        data: params,
                        success: function (result) {
                            if (result.code == 0) {
                                DGG.loading('close');
                                DGG.Succeed("操作成功!");
                                $("#myCloseAuditTable").dataTable().fnDraw(false);
                            } else {
                                DGG.loading('close');
                                DGG.Errors(result.msg)
                            }
                            layer.close(index);
                        }
                    });
                });
            },
            end: function () {
                DGG.loading('close');
            }
        })
    })
}






